﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/admin.master" AutoEventWireup="true" CodeFile="shipping-list.aspx.cs" Inherits="admin_shipping_list" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Namespace="ECommerce.Library.Web" TagPrefix="ucc" %>
<%@ Register Src="~/controls/wucAdminValidator.ascx" TagName="AdminValidator" TagPrefix="wuc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="AdminHeaderContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMiddleContent" Runat="Server">
    <script type="text/javascript">
        var CustomerName_Renderer = function (value, p, record, rowIndex) {
            var categoryUrl;
            categoryUrl = String.format("<%= SiteGlobals.BaseUrl %>" + "multiple_invoice_print.aspx?print=0&oid={0}", record.data.ProductPurchaseOrder_MultipleShippingInfoId);
            return String.format("<a href=\"{0}\" class=\"leftlink\" target=\"_blank\">{1}</a>", categoryUrl,  record.data.ShippingFirstName + " " + record.data.ShippingLastName);
        }
        var OrderTrackNumber_Renderer = function (value, p, record, rowIndex) {
            if (value == "")
                return String.format("<a href='#' onclick='BeginEditing({0})' class='leftlink'>Modify Shipping</a>", rowIndex);
            else
                return "Tracking# " + value;
        };
        var BeginEditing = function (rowIndex) {
            //alert('edit begin');
            if (categoryGrid != null) {
                var grid = categoryGrid;
                grid.getRowEditor().stopEditing();
                grid.getView().refresh();
                grid.getRowEditor().startEditing(rowIndex);
            }
        };
        var afterEdit = function (e) {

            e.grid.stopEditing();
            var trackingNumber = $("#<%= txtTrackingNumber.ClientID %>").val();
            //alert(trackingNumber);

            // Call DirectMethod
            Polana.WebService.UpdateOrder(e.record.data.OrderId, trackingNumber);
        };
        var CommandHandler = function (command, rowIndex, grid) {
            //showObj(grid);
            grid.getRowEditor().stopEditing();
            grid.getView().refresh();
            grid.getSelectionModel().selectRow(rowIndex);
            grid.getRowEditor().startEditing(rowIndex);
        }
        var categoryGrid;

        var onDocumentReady = function (grid) {
            categoryGrid = grid;
        }

    </script>
    <style type="text/css">
        .x-form-text
        {
            height: 16px !important;
            width: 100px;
        }
    </style>
    <ext:ResourceManager ID="ScriptManager1" runat="server" Theme="Gray">
        <Listeners>
            <DocumentReady Fn="onDocumentReady(#{GridPanel1})" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="Store1" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="ProductPurchaseOrder_MultipleShippingInfoId">
                <Fields>
                    <ext:RecordField Name="ProductPurchaseOrder_MultipleShippingInfoId" />
                    <ext:RecordField Name="OrderId" ServerMapping="OrderId" />
                    <ext:RecordField Name="ShippingFirstName" ServerMapping="ShippingFirstName"/>
                    <ext:RecordField Name="ShippingLastName" ServerMapping="ShippingLastName" />
                    <ext:RecordField Name="ShippingAddressLine1" ServerMapping="ShippingAddressLine1" />
                     <ext:RecordField Name="ShippingEmailAddress" ServerMapping="ShippingEmailAddress" />
                    <ext:RecordField Name="ShippingCost" ServerMapping="ShippingCost" />
                    <ext:RecordField Name="ShippingStatus" ServerMapping="ShippingStatus" />                    
                    <ext:RecordField Name="OrderTrackNumber" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <div class="admin-function-top inline">
        <ucc:ResponseMessage ID="uccResponseMessage" runat="server"></ucc:ResponseMessage>
        <ext:GridPanel ID="GridPanel1" runat="server" EnableViewState="true" AutoHeight="true"
            StoreID="Store1">
            <ColumnModel>
                <Columns>
                    <ext:Column Header="Name" DataIndex="ShippingFirstName" Width="60">
                        <Renderer Fn="CustomerName_Renderer" />
                    </ext:Column>
                    <ext:Column Header="Email" DataIndex="ShippingEmailAddress" Width="50">
                    </ext:Column>
                    <ext:Column Header="Address" DataIndex="ShippingAddressLine1" Width="50">
                    </ext:Column>
                    <ext:Column Width="60" DataIndex="OrderTrackNumber" Sortable="false">
                      <Renderer Fn="OrderTrackNumber_Renderer" />
                        <Editor>
                            <ext:TextField ID="txtTrackingNumber" runat="server" EmptyText="Tracking Number" />
                        </Editor>
                    </ext:Column>
                </Columns>
            </ColumnModel>
           
            <Plugins>
                <ext:RowEditor ID="rowedi" runat="server" SaveText="Update" ClicksToEdit="4" ErrorSummary="true"
                    ShowTooltip="={Ext.emptyFn}">
                    <Listeners>
                        <AfterEdit Fn="afterEdit" />
                    </Listeners>
                </ext:RowEditor>
            </Plugins>
            <Listeners>
                <Command Handler="CommandHandler(command, rowIndex, this)" />
            </Listeners>
            <View>
                <ext:GridView ID="GridView1" runat="server" ForceFit="true" />
            </View>
        </ext:GridPanel>
    </div>
         <script type="text/javascript">
        Ext.override(Ext.grid.GridView, {
            getEditorParent: function () {
                return document.body;
            }
        });
    </script>
</asp:Content>

